home *** CD-ROM | disk | FTP | other *** search
- # include "TransSkel.h"
-
- # include "MakeWrite.h"
-
-
- /*
- * Query user whether to replace the current font list with the
- * selected font, or just add them to the list. Return false if
- * Cancel clicked. If Replace clicked, then warn user that the
- * map will be destroyed (if it has been changed) and return false
- * if he declines. Otherwise return true.
- *
- * If Replace is selected, then the map and the font list are
- * cleared as well as setting some state variables. The map is
- * really modified by clearing it, but that was ok'd by user, so is
- * now considered clean (unmodified) - just like after New Map.
- */
-
- static Boolean
- ReplaceOrAdd (void)
- {
- typedef enum /* alert button numbers */
- {
- cancel = 1,
- add,
- replace
- };
- short i;
-
- i = SkelAlert (replaceAlrtNum, SkelDlogFilter (nil, true),
- skelPositionOnParentDevice);
- SkelRmveDlogFilter ();
- SkelDoUpdates ();
-
- if (i == cancel)
- return (false);
-
- if (i == replace)
- {
- if (!DestroyWarn ())
- return (false);
- ClobberMap ();
- ClearMapName ();
- ResetFontList ();
- mapModified = false;
- undoOp = noUndo;
- }
- return (true);
- }
-
-
- /*
- * Add the names of the FONT resources in the open resource files
- * to the font list (or replace the list with those fonts). */
-
- void
- ResourceFonts (Boolean ask)
- {
- short i;
- short fNum, nFonts;
- Str255 fontName;
- MenuHandle m;
-
- if (ask)
- {
- if (ReplaceOrAdd () == false)
- return;
- }
-
- m = NewMenu (tempMenuNum, "\p");
- AddResMenu (m, 'FONT');
- nFonts = CountMItems (m);
- for (i = 1; i <= nFonts; ++i)
- {
- GetItem (m, i, fontName);
- GetFNum (fontName, &fNum);
- if (!SetFontSpec (fNum, fontName))
- break;
- }
- SyncFontSpecs ();
- }
-
-
- /*
- * Add the fonts contained in the STR# whose id is fontStrNum
- * to the font list (or replace the list with those fonts).
- */
-
- void
- StrFonts (Boolean ask)
- {
- Handle h;
- short i, j, len;
- short nStrings;
- Str255 s;
- long fNum;
-
- if (ask)
- {
- if (ReplaceOrAdd () == false)
- return;
- }
-
- h = GetResource ('STR#', fontStrNum);
- nStrings = * (short *) *h;
-
- for (i = 0; i < nStrings; ++i)
- {
- GetIndString (s, fontStrNum, i + 1);
- if (s[1] == '#')
- continue; /* comment - ignore */
- len = s[0];
- j = 1;
- while (j <= len && s[j] != '/')
- ++j;
- if (j > len) /* error */
- {
- NumToString ((long) fontStrNum, s);
- Message3 ("\pA font list resource (STR# ", s,
- "\p) is messed up.");
- break;
- }
- s[0] = j - 1; /* length of numeric part */
- StringToNum (s, &fNum);
- s[j] = len - j;
- if (!SetFontSpec ((short) fNum, &s[j]))
- break;
- }
- ReleaseResource (h);
- SyncFontSpecs ();
- }
-